<table class="easyui-datagrid" id="potentials_list"
	   fit="true" border="false"
	   singleSelect="true" fitColumns="true" pagination="true"
	   idField="potentials_id" url="y.php?r=potentials/getdata" toolbar="#toolbar_potentials">
	<thead>
	<tr>
		<th field="potentials_name" width="60">销售机会名称</th>
		<th field="realname" width="60">客户</th>
		<th field="stage" width="80">销售阶段</th>
		<th field="possibility" width="60">成交可能性</th>
		<th field="duedate" width="60">成交日期</th>
		<th field="nextstep" width="60">下一阶段</th>
	</tr>
	</thead>
</table>
<div id="toolbar_potentials">
	<?php
	if (Yii::app()->user->checkAccess('potentials_module_view')) {
		?>
		<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-view',plain:true" onclick="potentials_view()" /a>
		<?php
	}
	if (Yii::app()->user->checkAccess('potentials_module_add')) {
		?>
		<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="loadWin('添加销售机会','y.php?r=potentials/showedit&potentials_id=0')" /a>
		<?php
	}
	if (Yii::app()->user->checkAccess('potentials_module_edit')) {
		?>
		<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="potentials_showedit()"/a>
		<?php
	}
	if (Yii::app()->user->checkAccess('potentials_module_remove')) {
		?>
		<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="potentials_remove()" />
		<?php
	}
	?>
</div>
<script>
	function potentials_showedit() {
		//获取选中的列
		var selected = $("#potentials_list").datagrid("getSelected");
		if(selected==null){
			alert('请选择行！');
		}else{
			//进行编辑操作
			loadWin('编辑销售机会','y.php?r=potentials/showedit&potentials_id='+selected.potentials_id);
		}
	}
	function potentials_remove() {
		var selected = $("#potentials_list").datagrid("getSelected");
		if(selected==null){
			alert('请选择行！');
		}else{
			$.messager.confirm('确认','您确认想要删除记录吗？',function(r){
				if (r){
					$.post('y.php?r=potentials/remove',{potentials_id:selected.potentials_id},function (res) {
						$("#potentials_list").datagrid("reload");
					});
				}
			});
		}
	}
	function potentials_view() {
		var selected = $("#potentials_list").datagrid("getSelected");
		if(selected==null){
			alert('请选择行！');
		}else{
			//进行编辑操作
			loadWin('查看销售机会','y.php?r=potentials/view&potentials_id='+selected.potentials_id);
		}
	}
</script>